package com.cmd.user;

import com.alibaba.fastjson.JSONObject;
import com.mgr.DriverOrderMgr;
import com.mgr.UserOrderMgr;
import com.player.User;
import com.qy.bean.OrderInfo;
import com.qy.util.StaticData;
import com.util.AbstractCommand;
import com.util.PBMessage;

/**
 * 用户订单详情
 * @author zwl 2018年2月1日
 */
public class OrderInfoCMD extends AbstractCommand {

    @Override
    public void execute(User user, PBMessage packet) throws Exception {
	/*
		 */
	JSONObject reJs = new JSONObject();
	reJs.put(StaticData.reKey.cmd.getKey(),packet.getCode());
	JSONObject param = packet.getMessage();
	if (!param.containsKey("orderId")) {
	    reJs.put(StaticData.reKey.code.getKey(),StaticData.codeType.param_error.getType());
	    user.sendPacket(reJs);
	    return;
	}
	// 订单号
	int orderId = param.getInteger("orderId");
	OrderInfo info = UserOrderMgr.getOrderInfo(orderId);
	if (info == null) {
	    reJs.put(StaticData.reKey.code.getKey(),StaticData.codeType.not_exist.getType());
	    user.sendPacket(reJs);
	    return;
	}
	reJs.put("orderBaseInfo", UserOrderMgr.OrderInfoForUser(info));
	
	
	if(info.getFDriver()!=0&&info.getFDriver()!=StaticData.no_param){
	    reJs.put("getCarObj", DriverOrderMgr.turnToPage(info.getFDriver()));
	}
	
	if(info.getSDriver()!=0&&info.getFDriver()!=StaticData.no_param){
	    reJs.put("checkCarObj", DriverOrderMgr.turnToPage(info.getSDriver()));
	}
	
	if(info.getTDriver()!=0&&info.getFDriver()!=StaticData.no_param){
	    reJs.put("backCarObj", DriverOrderMgr.turnToPage(info.getTDriver()));
	}
	
	reJs.put(StaticData.reKey.code.getKey(),StaticData.codeType.ok.getType());
	reJs.put(StaticData.reKey.cmd.getKey(),packet.getCode());
	user.sendPacket(reJs);
	return;
    }

}
